﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Pasteles.Controler
{
    public class StringProcessing
    {
        public StringProcessing()
        {
 
        }
        // Chuoi In Hoa Don
        public string stringReceipt(string a, string b, string c)
        {
            //in hoa don : moi sp la mot dong 32 ky tu
            int countName = 0;
            int countSl = 0;
            string chuoikq = "";
            float xulysoC = float.Parse(c);

            string atemp = "";
            string btemp = "";
            string ctemp = "";
            ctemp = xulysoC.ToString();
            a = a.Trim();
            b = b.Trim();
            c = c.Trim();
            ctemp = this.cutNo(c);
            if (a.Length >= 10)
            {
                atemp = a.Remove(9)+"  ";
            }
            else
            {
                countName = 9 - a.Length;
                atemp = a;
                for (int i = 0; i < countName; i++)
                {
                    atemp += " ";
                }
            }

            if (b.Length >= 3)
            {
                btemp = b;
            }
            else
            {
                countSl = 3 - b.Length;
                btemp = b;
                for (int i = 0; i < countSl; i++)
                {
                    btemp += " ";
                }
            }

            //if (ctemp.Length >= 7)
            //{

            //}
            //else
            //{
            //    countPrice = 6 - ctemp.Length;
            //    ctemp += "K";
            //    for (int i = 0; i < countPrice - 1; i++)
            //    {
            //        ctemp += " ";
            //    }
            //}

            chuoikq = btemp;

            //for (int i = 0; i <= 1; i++)
            //{
            //    chuoikq += " ";
            //}

            chuoikq += atemp;

            for (int i = 0; i <= 3; i++)
            {
                chuoikq += " ";
            }
            chuoikq += ctemp;
            return chuoikq+"\r\n";
        }

        //Chuoi don hang
        public string stringOrder(string c, string a, string b)
        {
            //in hoa don : moi sp la mot dong 32 ky tu

            int countName = 0;
            int countSl = 0;       
            string chuoikq = "";
            float xulysoC = float.Parse(c);
            string atemp = "";
            string btemp = "";
            string ctemp = "";
            a = a.Trim();
            b = b.Trim();
            c = c.Trim();
            if (a.Length >= 16)
            {
                atemp = a.Remove(15);
            }
            else
            {
                countName = 15 - a.Length;
                atemp = a;
                for (int i = 0; i < countName; i++)
                {
                    atemp += " ";
                }
            }

            if (b.Length >= 3)
            {
                btemp = b;
            }
            else
            {
                countSl = 3 - b.Length;
                btemp = b;
                for (int i = 0; i < countSl; i++)
                {
                    btemp += " ";
                }
            }

            if (c.Length >= 4)
            {
                ctemp = c;
            }
            else
            {
                countSl = 4 - b.Length;
                ctemp = c;
                for (int i = 0; i < countSl; i++)
                {
                    btemp += " ";
                }
            }

            chuoikq = ctemp;

            for (int i = 0; i <= 3; i++)
            {
                chuoikq += " ";
            }

            chuoikq += atemp;

            for (int i = 0; i <= 3; i++)
            {
                chuoikq += " ";
            }

            chuoikq += btemp;
            return chuoikq;
        }

        //Chuoi In Bao Cao Ca
        public string stringReport(string a, string b, string c)
        {
            //in hoa don : moi sp la mot dong 32 ky tu
            int countName = 0;
            string chuoikq = "";
            c.Replace(",", "");
            float xulysoC = float.Parse(c);
            xulysoC = xulysoC / 1000;

            string atemp = "";
            string ctemp = "";
            ctemp = xulysoC.ToString();
            a = a.Trim();
            b = b.Trim();
            c = c.Trim();
            atemp = a;

            if (a.Length >= 10)
            {
                atemp = a.Remove(9) + "  ";
            }
            else
            {
                countName = 9 - a.Length;
                atemp = a;
                for (int i = 0; i < countName; i++)
                {
                    atemp += " ";
                }
            }
            c = cutNo(c);
            chuoikq = b;
            for (int i = 0; i <= 2; i++)
            {
                chuoikq += " ";
            }
            chuoikq += atemp + "\r\n";
            chuoikq += c;
            return chuoikq;
        }

        //Ham them dau phai vao so thap phan tham so TextBox
        public void cutNo(TextBox _tb) 
        {
            string txt, txt1;
            txt1 = _tb.Text.Replace(",", "");
            txt = "";
            int n = txt1.Length;
            int dem = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                if (dem == 2 && i != 0)
                {
                    txt = "," + txt1.Substring(i, 1) + txt;
                    dem = 0;
                }
                else
                {
                    txt = txt1.Substring(i, 1) + txt;
                    dem += 1;
                }
            }
            _tb.Text = txt;
            _tb.SelectionStart = _tb.Text.Length;
        }
        //Ham them dau phay vao so thap phan tham so String
        public string cutNo(string stringPrint) 
        {
            string txt, txt1;
            txt1 = stringPrint.Replace(",", "");
            txt = "";
            int n = txt1.Length;
            int dem = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                if (dem == 2 && i != 0)
                {
                    txt = "," + txt1.Substring(i, 1) + txt;
                    dem = 0;
                }
                else
                {
                    txt = txt1.Substring(i, 1) + txt;
                    dem += 1;
                }
            }
            return txt;
        }
        public string reNo(string stringPrint)
        {
            string txt;
            txt = stringPrint.Replace(",", "");
            return txt;
        }
    }
}
